import itertools def fct(J,I): return([[I[0]+1,*I[1:I[0]],J[0],*I[I[0]:]],[*I[:I[0]+1],J[0],*I[I[0]+1:]]]) def calc (i,I): k=-1 l=-1 j=0 while (k+1)*(l+1)==0 and j0: I2=[*I[:l+1],i,*I[l+1:]] return([[1]+I0,[1]+I1,[-1]+I2]) return([[1]+I0,[1]+I1]) if k>0: if k